Architectural design

杨小鹤 Lv4

Intro

Software Design是后续开发步骤及软件维护工作的基础。如果没有设计,只能建立一个不稳定的系统结构

Def of Design:Design is the creative process of figuring out how to implement all of the customer’s requirements; the resulting plan is also called the design
每次设计都涉及到了建筑结构,后期设计决策涉及如何实现单个单元

如何设计:
利用现有解决方案的多种方法:(以前的设计经验可以重复使用)
1.克隆:完全借用设计/代码少量调整
2.参考模型:建议显示系统的通用体系结构
设计模式:详细设计,通用设计,用于一类

Design Process Model:
软件设计过程是一个迭代的过程
The final outcome is the software architecture document(输出是文档SAD)

分解视图:
1.High-level description of system’s key elements
2.Creating a hierarchy of information with increasing details

Some design problems have no existing solutions(无现存的方法)
Designers must decompose to isolate key problems

一些常用的办法:
1.Functional decomposition
2.Data-oriented decomposition
3.Process-oriented decomposition
4.Event-oriented decomposition
5.Object-oriented design

例子:Invoice processing system(发票处理系统)

Architectural design:
识别子系统并建立框架工作子系统控制和通信
是设计过程的第一阶段

例子:

Architectural Styles and Strategies
1.Pipes-and-Filter
2.Client-Server
3.Peer-to-Peer
4.Publish-Subscribe
5.Repositories
6.Layering

Pipes and Filter(有点类似dataflow)

The system has
  Streams of data (pipe) for input and output
  Transformation of the data (filter)

一些重要的性质:
1.设计者可以理解整个系统的effect on 输入输出,作为滤波器的组成(可以多输入)
2.滤波器可以很容易被其他系统重新使用
3.系统的evolution很容易
4.Allow concurrent execution of filters(可以并行执行)

缺点:不利于处理一些互动的应用
发票处理系统例子:

Client-Server(客户机 服务器)

两类组成:
Server:提供服务
Client:access them using a request/reply protocol
可能会有多个服务器,不同服务器接受不同的服务
两个中间通过Internet进行连接

Peer-to-Peer(P2P)

只有一类节点,这类节点同时具备Client和Server的功能,每个节点也能发送请求,也能接受请求 提供服务

特点:容易扩展;提升系统容错性;容量大

Publish-Subscribe

也包含若干个节点,通过网络连接
组件通过广播和活动进行交互
每个节点都能发布消息和事件,也能通过它的兴趣去订阅相关事件

当另一个结点让事件发生了,订阅的结点就会响应去做相关的动作

repository(仓库)

两个组件:
a central data store(中央数据存储)
A collection of components that operate on it to store, retrieve, and update information(对中央数据存储操作的一系列结点)
包括增删改查

特点:The challenge is deciding how the components will interact
如果是传统的数据库:transactions trigger process execution(正在运行的事务触发进程执行)

如果是Blackboard:the central store controls the triggering process(控制引发流程)

黑板系统:黑板上的数据对参与者都是可见的,对黑板上的数据进行推理,根据推理的结果智能修改内容(增删改查)

专家系统:在某一特定领域中,能够像人类专家一样解决复杂问题的计算机软件系统

Example:

优点:中央数据存储提供一种统一的方法去操作数据
缺点:有时候有点也是缺点,如果一个数据模式改变了,所有的都得变(得让所有组件都接受信息)

Layering

也称为:abstract machine model

划分多个层次,每个层次给上面层次提供服务,对下面层次发送请求提供服务
程序不是直接访问数据库,使用对象获得数据,程序的其他部分操作对象

优点:
层次性高度抽象,层次3修改不需要改层次1,可移植性好,容易增加一层

缺点:
性能上损失,并不是很容易建立结构

Combining Architectural Styles

很少有只使用但以一种结构的软件
一般使用组合,Architectural styles can be combined in several ways:
1.Use different styles at different layers

2.Use mixture of styles to model different components or types of interaction

如果是混合的,文档就要解释关系
If architecture is expressed as collection of models, documentation must be created to show relation between models

Control styles

之前的都是关注与系统的静态结构
这个Control styles关注的是动态,模块之间如何动态控制

Two generic control styles
 Centralized control:有一个模块控制其他模块的运行,是中央控制模块
   两个子模式:
     Call-return model:调用返回模型(类似于树的遍历执行,按顺序执行)

     manager model:并行执行,one system component is designated as a system manager and controls the starting, stopping and coordination of other system processes

 Event-based control:没有中央控制模块,所有模块对事件进行响应然后运行,事件驱动
  两个子系统:
     Broadcast models:所有事件被广播到所有结点上,感兴趣的结果进行响应(优点:结构简单,缺点:开销大)
     Interrupt-driven models:订阅感兴趣的时候,发送到Interrupt vector 发送到对应感兴趣的节点

Design Principles

Def of Modularity:Modularity is the principle of keeping separate the various unrelated aspects of a system, so that each aspect can be studied in isolation

应该具有的特点:
1.容易定位错误
2.每个模块容易理解开发
3.Easier to change the system (because a change to one module affects relatively few other modules

用coupling and cohesion来描述module的独立程度(见前面)
Coupling:模块间的,越稀疏越好
Cohesion:模块内元素,越紧越好

用图来描述:
Fan-in refers to the number of units that use a particular software unit(输入边的度数)(不破坏独立性下,越大越好)
Fan-out refers to the number of units used by particular software unit(输出边的度数)(通常3到9)
需要选择合适的深度和宽度

也可以利用sandwiching的技术破坏循环:把一个模块划分成两个不相关的模块,关系链就会被打破
依赖链的长度(路径长度)越短越好,也可以用sandwiching打破依赖链

  • Title: Architectural design
  • Author: 杨小鹤
  • Created at: 2024-02-01 14:26:08
  • Updated at: 2023-10-27 15:59:57
  • Link: https://redefine.ohevan.com/2024/02/01/SW/sw8/
  • License: This work is licensed under CC BY-NC-SA 4.0.
 Comments